package flc.ast.activity;


import android.os.Bundle;
import android.util.Log;
import android.view.View;

import androidx.annotation.Nullable;

import com.blankj.utilcode.util.ToastUtils;

import java.util.ArrayList;
import java.util.List;

import flc.ast.BaseAc;
import flc.ast.R;
import flc.ast.bean.MyRecordBean;
import flc.ast.databinding.ActivityFindResultBinding;
import flc.ast.utils.AppSpUtils;
import stark.common.apis.ApiManager;
import stark.common.apis.base.JtwzdmQueryBean;
import stark.common.base.IReqRetCallback;
import stark.common.basic.event.EventStatProxy;

public class FindResultActivity extends BaseAc<ActivityFindResultBinding> {

    public static String code;

    @Override
    protected int onCreate() {
        return R.layout.activity_find_result;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent1(this,mDataBinding.event1Container);
        mDataBinding.ivFindResultBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
    }

    @Override
    protected void initData() {
        if (code.isEmpty()) return;
        ApiManager.toolKitApi().jtwzdmQuery(this, code, new IReqRetCallback<JtwzdmQueryBean>() {
            @Override
            public void onResult(boolean success, String msg, @Nullable JtwzdmQueryBean result) {
                if (success){
                    mDataBinding.llFindResult.setVisibility(View.VISIBLE);
                    mDataBinding.tvFindNoData.setVisibility(View.GONE);
                    mDataBinding.tvPeccancyCode.setText(getString(R.string.peccancy_code)+result.code);
                    mDataBinding.tvPeccancyBehavior.setText(getString(R.string.peccancy_behavior)+result.illegal);
                    mDataBinding.tvPeccancyResult.setText(getString(R.string.punishment_result)+result.others);
                    mDataBinding.tvPeccancyAmount.setText(getString(R.string.fine_amount)+result.fine);
                    mDataBinding.tvPeccancyScore.setText(getString(R.string.score,result.points));
                    save(result);
                }else {
                    mDataBinding.llFindResult.setVisibility(View.GONE);
                    mDataBinding.tvFindNoData.setVisibility(View.VISIBLE);
                }
            }
        });
    }

    private void save(JtwzdmQueryBean bean){
        List<JtwzdmQueryBean> listSave = new ArrayList<>();
        listSave.add(bean);
        List<JtwzdmQueryBean> listSp = AppSpUtils.getHisotryList();
        if (listSp != null && listSp.size() > 0) {
            listSp.addAll(listSave);
            AppSpUtils.saveHistoryList(listSp);
        } else {
            AppSpUtils.saveHistoryList(listSave);
        }
    }

}